package test;

public class BuildTree {
    public int getDistanceBwTrees(int num, int[][] areas) {
        int numAll = 0;
        int begin = 0;
        int end = 0;

        for (int i = 0; i < areas.length; i++) {
            begin = areas[i][0];
            end = areas[i][1];

            while (begin <= end) {
                numAll++;
                begin = begin + 2;
            }
        }

        if (numAll < num) {
            return -1;
        }
        return 2;
    }

    public static void main(String[] args) {
        System.out.println(new BuildTree().getDistanceBwTrees(5, new int[][] {{1,3},{5,6}, {8,9},{10,11}}));
    }
}
